import { reqGoodsInfo, reqAddOrUpdateShopCart } from "../../api";
//封装游客身份模块
import {getUUID} from "@/utils/uuid_token";
const state = {
    goodsInfo: {},
    //游客临时身份
    uuid_token:getUUID()
};
const mutations = {
    GETGOODSINFO(state, goodsInfo) {
        state.goodsInfo = goodsInfo
    }
};
const actions = {
    async getGoodsInfo({ commit }, skuId) {
        let result = await reqGoodsInfo(skuId);
        if (result.code == 200) {
            commit('GETGOODSINFO', result.data)
        }
    },
    async addOrUpdateShopCart({ commit }, { skuId, skuNum }) {
        //发请求:前端带一些参数给服务器【需要存储这些数据】，存储成功了，没有给返回数据
        //不需要在三连环（仓库存储数据了）
        //注意:async函数执行返回的结果一定是一个promise【要么成功，要么失败】
        let result = await reqAddOrUpdateShopCart(skuId, skuNum);
        if (result.code == 200) {
            return '成功';
        } else {
            return Promise.reject(new Error('faile'));
        }
    }
};
const getters = {
    //路径导航简化数据
    categoryView(state) {
        return state.goodsInfo.categoryView || {};
    },
    //产品信息简化数据
    skuInfo(state) {
        return state.goodsInfo.skuInfo || {};
    },
    //产品售卖属性数据
    spuSaleAttrList(state) {
        return state.goodsInfo.spuSaleAttrList || [];
    },

};
export default {
    state,
    mutations,
    actions,
    getters
}